import React from "react"
import GpContainer from "@/components/GpContainer"
import { tabbarPages } from "@/constants/pageMap"
import { navigation } from "@/utils/router"
import { syncTabbarActive } from "@/utils/tabbar"

import { connect, ConnectedProps } from "react-redux"
import { IRootState } from "@/store/index"

const mapState = (state: IRootState) => ({
  areaId: state.auth.userInfo.areaId,
  projectId: state.auth.userInfo.projectId
})

// 注意：需要传第四个参数处理forwardRef,否则小程序页面生命周期方法可能不会被触发
const connector = connect(mapState, null, null, { forwardRef: true })

type IPropsFromRedux = ConnectedProps<typeof connector>

type IProps = IPropsFromRedux & {
  [key: string]: any
}

class Institution extends React.Component<IProps> {
  onShareAppMessage() {}
  componentDidShow() {
    try {
      syncTabbarActive(tabbarPages.institution)

      wx.reportEvent("jg0722", {})
    } catch (error) {}

    // 导航到插件
    navigation(
      tabbarPages.gpPluginInstitution,
      {
        // 传入来源艺考
        gpscene: "yikao",
        // 传入来源地区，当前选中的地区
        gparea: this.props.areaId && this.props.areaId != "000000" ? this.props.areaId : "",
        gpchannelvalue:
          this.props.projectId && this.props.projectId !== 3 ? this.props.projectId : ""
      },
      "reLaunch",
      false,
      true
    )
  }
  render() {
    return <GpContainer className="professional"></GpContainer>
  }
}
export default connector(Institution)
